package h0715;

import java.util.Arrays;
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
  * @description 火星文计算
  * @author 不知名帅哥
  * @date 2024/7/15 19:34
  * @version 1.0
*/
public class LeetSpeakCompute2 {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        String str = sc.next();
        System.out.println(getResult(str));
    }

    private static long getResult(String str) {
        Pattern p=Pattern.compile("(\\d+)\\$(\\d+)");
        while (true){
            Matcher m = p.matcher(str);
            if (!m.find()) break;

            String subStr = m.group(0);
            long x = Long.parseLong(m.group(1));
            long y=Long.parseLong(m.group(2));
            String replace = subStr.replace("$", "\\$");
            str=str.replaceFirst(replace,3*x+y+2+"");
        }
        return Arrays.stream(str.split("#")).map(Long::parseLong).reduce((x,y)->2*x+3*y+4).orElse(0L);
    }
}
